USE [eShop]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_EmployeeInfo_EmployeePWD]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[T_Employee_Info] DROP CONSTRAINT [DF_EmployeeInfo_EmployeePWD]
END

GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_T_Employee_Info_Sex]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[T_Employee_Info] DROP CONSTRAINT [DF_T_Employee_Info_Sex]
END

GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_T_Employee_Info_IsGregorianCalendar]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[T_Employee_Info] DROP CONSTRAINT [DF_T_Employee_Info_IsGregorianCalendar]
END

GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_EmployeeInfo_CreateDatetime]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[T_Employee_Info] DROP CONSTRAINT [DF_EmployeeInfo_CreateDatetime]
END

GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_EmployeeInfo_EmployeePurview]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[T_Employee_Info] DROP CONSTRAINT [DF_EmployeeInfo_EmployeePurview]
END

GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_MemberInfo_LevelID]') AND parent_object_id = OBJECT_ID(N'[dbo].[T_Member_BasicInfo]'))
ALTER TABLE [dbo].[T_Member_BasicInfo] DROP CONSTRAINT [FK_MemberInfo_LevelID]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_MemberInfo_CreateTime]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[T_Member_BasicInfo] DROP CONSTRAINT [DF_MemberInfo_CreateTime]
END

GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_T_Member_BasicInfo_Type]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[T_Member_BasicInfo] DROP CONSTRAINT [DF_T_Member_BasicInfo_Type]
END

GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_MrchandiseBasicInfo_MerchandiseClassID]') AND parent_object_id = OBJECT_ID(N'[dbo].[T_Merchandise_BasicInfo]'))
ALTER TABLE [dbo].[T_Merchandise_BasicInfo] DROP CONSTRAINT [FK_MrchandiseBasicInfo_MerchandiseClassID]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_MrchandiseBasicInfo_MerchandiseUnitID]') AND parent_object_id = OBJECT_ID(N'[dbo].[T_Merchandise_BasicInfo]'))
ALTER TABLE [dbo].[T_Merchandise_BasicInfo] DROP CONSTRAINT [FK_MrchandiseBasicInfo_MerchandiseUnitID]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_MerchandiseBasicInfo_AlertNum]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[T_Merchandise_BasicInfo] DROP CONSTRAINT [DF_MerchandiseBasicInfo_AlertNum]
END

GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_MerchandiseOrder_MemberID]') AND parent_object_id = OBJECT_ID(N'[dbo].[T_Merchandise_Order]'))
ALTER TABLE [dbo].[T_Merchandise_Order] DROP CONSTRAINT [FK_MerchandiseOrder_MemberID]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_MerchandiseOrderDetail_Barcode]') AND parent_object_id = OBJECT_ID(N'[dbo].[T_Merchandise_OrderDetail]'))
ALTER TABLE [dbo].[T_Merchandise_OrderDetail] DROP CONSTRAINT [FK_MerchandiseOrderDetail_Barcode]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_MerchandiseOrderDetail_OrderID]') AND parent_object_id = OBJECT_ID(N'[dbo].[T_Merchandise_OrderDetail]'))
ALTER TABLE [dbo].[T_Merchandise_OrderDetail] DROP CONSTRAINT [FK_MerchandiseOrderDetail_OrderID]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_MerchandiseOrderDetail_StockInOrder]') AND parent_object_id = OBJECT_ID(N'[dbo].[T_Merchandise_OrderDetail]'))
ALTER TABLE [dbo].[T_Merchandise_OrderDetail] DROP CONSTRAINT [FK_MerchandiseOrderDetail_StockInOrder]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_MerchandiseOrderDetail_SaleTime]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[T_Merchandise_OrderDetail] DROP CONSTRAINT [DF_MerchandiseOrderDetail_SaleTime]
END

GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_MerchandiseSell_StockInOrder]') AND parent_object_id = OBJECT_ID(N'[dbo].[T_Merchandise_Sell]'))
ALTER TABLE [dbo].[T_Merchandise_Sell] DROP CONSTRAINT [FK_MerchandiseSell_StockInOrder]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_MerchandiseSell_SellQuantity]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[T_Merchandise_Sell] DROP CONSTRAINT [DF_MerchandiseSell_SellQuantity]
END

GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_MerchandiseSell_SellPrice]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[T_Merchandise_Sell] DROP CONSTRAINT [DF_MerchandiseSell_SellPrice]
END

GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_MerchandiseSell_SalePrice]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[T_Merchandise_Sell] DROP CONSTRAINT [DF_MerchandiseSell_SalePrice]
END

GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_StockIn_Barcode]') AND parent_object_id = OBJECT_ID(N'[dbo].[T_Stock_In]'))
ALTER TABLE [dbo].[T_Stock_In] DROP CONSTRAINT [FK_StockIn_Barcode]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_StockIn_IsStatu]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[T_Stock_In] DROP CONSTRAINT [DF_StockIn_IsStatu]
END

GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_StockIn_Barcode]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[T_Stock_In] DROP CONSTRAINT [DF_StockIn_Barcode]
END

GO

USE [eShop]
GO

/****** Object:  Table [dbo].[T_Employee_Info]    Script Date: 10/16/2011 05:49:15 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[T_Employee_Info]') AND type in (N'U'))
DROP TABLE [dbo].[T_Employee_Info]
GO

/****** Object:  Table [dbo].[T_Level_Info]    Script Date: 10/16/2011 05:49:15 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[T_Level_Info]') AND type in (N'U'))
DROP TABLE [dbo].[T_Level_Info]
GO

/****** Object:  Table [dbo].[T_Member_BasicInfo]    Script Date: 10/16/2011 05:49:15 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[T_Member_BasicInfo]') AND type in (N'U'))
DROP TABLE [dbo].[T_Member_BasicInfo]
GO

/****** Object:  Table [dbo].[T_Member_Score_Value]    Script Date: 10/16/2011 05:49:15 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[T_Member_Score_Value]') AND type in (N'U'))
DROP TABLE [dbo].[T_Member_Score_Value]
GO

/****** Object:  Table [dbo].[T_Merchandise_BasicInfo]    Script Date: 10/16/2011 05:49:15 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[T_Merchandise_BasicInfo]') AND type in (N'U'))
DROP TABLE [dbo].[T_Merchandise_BasicInfo]
GO

/****** Object:  Table [dbo].[T_Merchandise_Class]    Script Date: 10/16/2011 05:49:15 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[T_Merchandise_Class]') AND type in (N'U'))
DROP TABLE [dbo].[T_Merchandise_Class]
GO

/****** Object:  Table [dbo].[T_Merchandise_Order]    Script Date: 10/16/2011 05:49:15 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[T_Merchandise_Order]') AND type in (N'U'))
DROP TABLE [dbo].[T_Merchandise_Order]
GO

/****** Object:  Table [dbo].[T_Merchandise_OrderDetail]    Script Date: 10/16/2011 05:49:15 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[T_Merchandise_OrderDetail]') AND type in (N'U'))
DROP TABLE [dbo].[T_Merchandise_OrderDetail]
GO

/****** Object:  Table [dbo].[T_Merchandise_Sell]    Script Date: 10/16/2011 05:49:15 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[T_Merchandise_Sell]') AND type in (N'U'))
DROP TABLE [dbo].[T_Merchandise_Sell]
GO

/****** Object:  Table [dbo].[T_Merchandise_Unit]    Script Date: 10/16/2011 05:49:15 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[T_Merchandise_Unit]') AND type in (N'U'))
DROP TABLE [dbo].[T_Merchandise_Unit]
GO

/****** Object:  Table [dbo].[T_Stock_In]    Script Date: 10/16/2011 05:49:15 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[T_Stock_In]') AND type in (N'U'))
DROP TABLE [dbo].[T_Stock_In]
GO

USE [eShop]
GO

/****** Object:  Table [dbo].[T_Employee_Info]    Script Date: 10/16/2011 05:49:15 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[T_Employee_Info](
	[ID] [int] IDENTITY(1000,1) NOT NULL,
	[EmployeeID]  AS ('COLOUR'+CONVERT([varchar](6),[ID],(0))),
	[EmployeePWD] [varchar](50) NOT NULL,
	[FullName] [varchar](50) NOT NULL,
	[EmployeePID] [varchar](18) NOT NULL,
	[Sex] [bit] NOT NULL,
	[Brithday] [datetime] NULL,
	[IsGregorianCalendar] [bit] NULL,
	[Popedom] [varchar](50) NULL,
	[Address] [varchar](255) NULL,
	[Mobile] [varchar](12) NOT NULL,
	[Remark] [text] NULL,
	[CreateDatetime] [datetime] NOT NULL,
	[LastLoginDatetime] [datetime] NULL,
	[EmployeePurview] [int] NULL,
 CONSTRAINT [PK_EmployeeInfo_ID] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [eShop]
GO

/****** Object:  Table [dbo].[T_Level_Info]    Script Date: 10/16/2011 05:49:15 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[T_Level_Info](
	[LevelID] [int] IDENTITY(1,1) NOT NULL,
	[LevelName] [varchar](50) NULL,
	[LevelDiscount] [decimal](3, 2) NULL,
 CONSTRAINT [PK_LevelInfo_LevelID] PRIMARY KEY CLUSTERED 
(
	[LevelID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [eShop]
GO

/****** Object:  Table [dbo].[T_Member_BasicInfo]    Script Date: 10/16/2011 05:49:15 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[T_Member_BasicInfo](
	[MemberID] [varchar](20) NOT NULL,
	[MemberName] [varchar](50) NULL,
	[MemberSex] [bit] NULL,
	[Brithday] [datetime] NULL,
	[IsGregorianCalendar] [bit] NULL,
	[MemberAddress] [varchar](255) NULL,
	[MemberMobel] [varchar](12) NULL,
	[LevelID] [int] NULL,
	[CreateTime] [datetime] NULL,
	[Type] [int] NOT NULL,
	[Remark] [text] NULL,
 CONSTRAINT [PK_MemberInfo_MemberID] PRIMARY KEY CLUSTERED 
(
	[MemberID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'0,普通會員;1,系統會員;2,會員已停用' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'T_Member_BasicInfo', @level2type=N'COLUMN',@level2name=N'Type'
GO

USE [eShop]
GO

/****** Object:  Table [dbo].[T_Member_Score_Value]    Script Date: 10/16/2011 05:49:15 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[T_Member_Score_Value](
	[MemberID] [varchar](20) NOT NULL,
	[MemberScoreValue] [int] NULL,
	[IsLimitTime] [bit] NULL,
	[LastLimitTime] [datetime] NULL,
 CONSTRAINT [PK_MemberScoreValue_MemberID] PRIMARY KEY CLUSTERED 
(
	[MemberID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [eShop]
GO

/****** Object:  Table [dbo].[T_Merchandise_BasicInfo]    Script Date: 10/16/2011 05:49:15 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[T_Merchandise_BasicInfo](
	[Barcode] [varchar](30) NOT NULL,
	[MerchandiseClassID] [int] NOT NULL,
	[MerchandiseName] [varchar](50) NOT NULL,
	[MerchandiseUnitID] [int] NOT NULL,
	[MerchandiseResume] [text] NULL,
	[MerchandiseRemark] [text] NULL,
	[IsAlert] [bit] NULL,
	[AlertNum] [int] NULL,
	[HasOverTime] [bit] NULL,
 CONSTRAINT [PK_MrchandiseBasicInfo_Barcode] PRIMARY KEY CLUSTERED 
(
	[Barcode] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [eShop]
GO

/****** Object:  Table [dbo].[T_Merchandise_Class]    Script Date: 10/16/2011 05:49:15 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[T_Merchandise_Class](
	[MerchandiseClassID] [int] IDENTITY(1,1) NOT NULL,
	[MerchandiseClassName] [varchar](50) NULL,
	[MerchandiseClassResume] [text] NULL,
	[MerchandiseClassRemark] [text] NULL,
 CONSTRAINT [PK_MerchandiseClass_MerchandiseClassID] PRIMARY KEY CLUSTERED 
(
	[MerchandiseClassID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [eShop]
GO

/****** Object:  Table [dbo].[T_Merchandise_Order]    Script Date: 10/16/2011 05:49:15 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[T_Merchandise_Order](
	[OrderID] [int] IDENTITY(1,1) NOT NULL,
	[PayAmount] [money] NULL,
	[MemberID] [varchar](20) NULL,
	[Discount] [decimal](3, 2) NULL,
	[RealAmount] [money] NULL,
	[EmployeeID] [varchar](12) NULL,
	[OrderRemark] [text] NULL,
	[SellTime] [datetime] NULL,
 CONSTRAINT [PK_MerchandiseOrder_OrderID] PRIMARY KEY CLUSTERED 
(
	[OrderID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [eShop]
GO

/****** Object:  Table [dbo].[T_Merchandise_OrderDetail]    Script Date: 10/16/2011 05:49:15 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[T_Merchandise_OrderDetail](
	[SerialNumber] [varchar](20) NOT NULL,
	[OrderID] [int] NULL,
	[Barcode] [varchar](30) NULL,
	[StockInOrder] [int] NULL,
	[BuyNumber] [int] NULL,
	[SellPrice] [money] NULL,
	[SaleAmount] [money] NULL,
	[SaleTime] [datetime] NULL,
 CONSTRAINT [PK_MerchandiseOrderDetail_SerialNumber] PRIMARY KEY CLUSTERED 
(
	[SerialNumber] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [eShop]
GO

/****** Object:  Table [dbo].[T_Merchandise_Sell]    Script Date: 10/16/2011 05:49:15 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[T_Merchandise_Sell](
	[Barcode] [varchar](30) NOT NULL,
	[StockInOrder] [int] NULL,
	[SellQuantity] [int] NULL,
	[SellPrice] [money] NULL,
	[SalePrice] [money] NULL,
	[SellTime] [datetime] NULL,
 CONSTRAINT [PK_MerchandiseSell_Barcode] PRIMARY KEY CLUSTERED 
(
	[Barcode] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [eShop]
GO

/****** Object:  Table [dbo].[T_Merchandise_Unit]    Script Date: 10/16/2011 05:49:15 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[T_Merchandise_Unit](
	[UnitID] [int] IDENTITY(1,1) NOT NULL,
	[UnitName] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_T_Merchandise_Unit] PRIMARY KEY CLUSTERED 
(
	[UnitID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

USE [eShop]
GO

/****** Object:  Table [dbo].[T_Stock_In]    Script Date: 10/16/2011 05:49:15 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[T_Stock_In](
	[StockInOrder] [int] IDENTITY(1,1) NOT NULL,
	[Barcode] [varchar](30) NULL,
	[StockInNum] [int] NULL,
	[UnitPrice] [money] NULL,
	[TotalPrice] [money] NULL,
	[IsStatu] [int] NULL,
	[OverTime] [datetime] NULL,
	[StockInTime] [datetime] NULL,
 CONSTRAINT [PK_StockIn_StockInOrder] PRIMARY KEY CLUSTERED 
(
	[StockInOrder] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[T_Employee_Info] ADD  CONSTRAINT [DF_EmployeeInfo_EmployeePWD]  DEFAULT ('888888') FOR [EmployeePWD]
GO

ALTER TABLE [dbo].[T_Employee_Info] ADD  CONSTRAINT [DF_T_Employee_Info_Sex]  DEFAULT ((1)) FOR [Sex]
GO

ALTER TABLE [dbo].[T_Employee_Info] ADD  CONSTRAINT [DF_T_Employee_Info_IsGregorianCalendar]  DEFAULT ((1)) FOR [IsGregorianCalendar]
GO

ALTER TABLE [dbo].[T_Employee_Info] ADD  CONSTRAINT [DF_EmployeeInfo_CreateDatetime]  DEFAULT (getdate()) FOR [CreateDatetime]
GO

ALTER TABLE [dbo].[T_Employee_Info] ADD  CONSTRAINT [DF_EmployeeInfo_EmployeePurview]  DEFAULT ((0)) FOR [EmployeePurview]
GO

ALTER TABLE [dbo].[T_Member_BasicInfo]  WITH CHECK ADD  CONSTRAINT [FK_MemberInfo_LevelID] FOREIGN KEY([LevelID])
REFERENCES [dbo].[T_Level_Info] ([LevelID])
GO

ALTER TABLE [dbo].[T_Member_BasicInfo] CHECK CONSTRAINT [FK_MemberInfo_LevelID]
GO

ALTER TABLE [dbo].[T_Member_BasicInfo] ADD  CONSTRAINT [DF_MemberInfo_CreateTime]  DEFAULT (getdate()) FOR [CreateTime]
GO

ALTER TABLE [dbo].[T_Member_BasicInfo] ADD  CONSTRAINT [DF_T_Member_BasicInfo_Type]  DEFAULT ((0)) FOR [Type]
GO

ALTER TABLE [dbo].[T_Merchandise_BasicInfo]  WITH CHECK ADD  CONSTRAINT [FK_MrchandiseBasicInfo_MerchandiseClassID] FOREIGN KEY([MerchandiseClassID])
REFERENCES [dbo].[T_Merchandise_Class] ([MerchandiseClassID])
GO

ALTER TABLE [dbo].[T_Merchandise_BasicInfo] CHECK CONSTRAINT [FK_MrchandiseBasicInfo_MerchandiseClassID]
GO

ALTER TABLE [dbo].[T_Merchandise_BasicInfo]  WITH CHECK ADD  CONSTRAINT [FK_MrchandiseBasicInfo_MerchandiseUnitID] FOREIGN KEY([MerchandiseUnitID])
REFERENCES [dbo].[T_Merchandise_Unit] ([UnitID])
GO

ALTER TABLE [dbo].[T_Merchandise_BasicInfo] CHECK CONSTRAINT [FK_MrchandiseBasicInfo_MerchandiseUnitID]
GO

ALTER TABLE [dbo].[T_Merchandise_BasicInfo] ADD  CONSTRAINT [DF_MerchandiseBasicInfo_AlertNum]  DEFAULT ((0)) FOR [AlertNum]
GO

ALTER TABLE [dbo].[T_Merchandise_Order]  WITH CHECK ADD  CONSTRAINT [FK_MerchandiseOrder_MemberID] FOREIGN KEY([MemberID])
REFERENCES [dbo].[T_Member_BasicInfo] ([MemberID])
GO

ALTER TABLE [dbo].[T_Merchandise_Order] CHECK CONSTRAINT [FK_MerchandiseOrder_MemberID]
GO

ALTER TABLE [dbo].[T_Merchandise_OrderDetail]  WITH CHECK ADD  CONSTRAINT [FK_MerchandiseOrderDetail_Barcode] FOREIGN KEY([Barcode])
REFERENCES [dbo].[T_Merchandise_BasicInfo] ([Barcode])
GO

ALTER TABLE [dbo].[T_Merchandise_OrderDetail] CHECK CONSTRAINT [FK_MerchandiseOrderDetail_Barcode]
GO

ALTER TABLE [dbo].[T_Merchandise_OrderDetail]  WITH CHECK ADD  CONSTRAINT [FK_MerchandiseOrderDetail_OrderID] FOREIGN KEY([OrderID])
REFERENCES [dbo].[T_Merchandise_Order] ([OrderID])
GO

ALTER TABLE [dbo].[T_Merchandise_OrderDetail] CHECK CONSTRAINT [FK_MerchandiseOrderDetail_OrderID]
GO

ALTER TABLE [dbo].[T_Merchandise_OrderDetail]  WITH CHECK ADD  CONSTRAINT [FK_MerchandiseOrderDetail_StockInOrder] FOREIGN KEY([StockInOrder])
REFERENCES [dbo].[T_Stock_In] ([StockInOrder])
GO

ALTER TABLE [dbo].[T_Merchandise_OrderDetail] CHECK CONSTRAINT [FK_MerchandiseOrderDetail_StockInOrder]
GO

ALTER TABLE [dbo].[T_Merchandise_OrderDetail] ADD  CONSTRAINT [DF_MerchandiseOrderDetail_SaleTime]  DEFAULT (getdate()) FOR [SaleTime]
GO

ALTER TABLE [dbo].[T_Merchandise_Sell]  WITH CHECK ADD  CONSTRAINT [FK_MerchandiseSell_StockInOrder] FOREIGN KEY([StockInOrder])
REFERENCES [dbo].[T_Stock_In] ([StockInOrder])
GO

ALTER TABLE [dbo].[T_Merchandise_Sell] CHECK CONSTRAINT [FK_MerchandiseSell_StockInOrder]
GO

ALTER TABLE [dbo].[T_Merchandise_Sell] ADD  CONSTRAINT [DF_MerchandiseSell_SellQuantity]  DEFAULT ((0)) FOR [SellQuantity]
GO

ALTER TABLE [dbo].[T_Merchandise_Sell] ADD  CONSTRAINT [DF_MerchandiseSell_SellPrice]  DEFAULT ((0)) FOR [SellPrice]
GO

ALTER TABLE [dbo].[T_Merchandise_Sell] ADD  CONSTRAINT [DF_MerchandiseSell_SalePrice]  DEFAULT ((0)) FOR [SalePrice]
GO

ALTER TABLE [dbo].[T_Stock_In]  WITH CHECK ADD  CONSTRAINT [FK_StockIn_Barcode] FOREIGN KEY([Barcode])
REFERENCES [dbo].[T_Merchandise_BasicInfo] ([Barcode])
GO

ALTER TABLE [dbo].[T_Stock_In] CHECK CONSTRAINT [FK_StockIn_Barcode]
GO

ALTER TABLE [dbo].[T_Stock_In] ADD  CONSTRAINT [DF_StockIn_IsStatu]  DEFAULT ((0)) FOR [IsStatu]
GO

ALTER TABLE [dbo].[T_Stock_In] ADD  CONSTRAINT [DF_StockIn_Barcode]  DEFAULT (getdate()) FOR [StockInTime]
GO

